#include"head.h"
#include"common.h"
#include"ip.h"
#include"nat.h"
#include"conn.h"
int main(int argc, char *argv[]) {
	if(argc<3) {
		printf("wrong cmd\n");
		return 0;
	}
	struct KernelResponse rsp;

	// 过滤规则相关
	if(strcmp(argv[1], "rule")==0 ) {
		if(strcmp(argv[2], "ls")==0 ) {
		// 列出所有过滤规则
			 rsp = getAllFilterRules();
			printf("%d\n", rsp.arrlen);
			showRules((struct IPRule*)rsp.data, rsp.arrlen);
			return 0;
		} else if(strcmp(argv[2], "del")==0) {
		// 删除过滤规则
			if(argc < 4)
				printf("Please point rule name in option.\n");
			else if(strlen(argv[3])> 6 )
				printf("rule name too long!");
			else
				rsp = delFilterRule(argv[3],sizeof(argv[3]));
		} else if(strcmp(argv[2], "add")==0) {
		// 添加过滤规则
			 rsp = cmdAddRule();
			
		} 
		
	 } 
	 else if(strcmp(argv[1], "nat")==0) {
		if(strcmp(argv[2], "ls")==0 ) {
		// 列出所有NAT规则
			 rsp = getAllNATRules();
			 showNATRules((struct NATRecord*)rsp.data, rsp.arrlen);
		} else if(strcmp(argv[2], "del")==0) {
			if(argc < 4)
				printf("Please point rule number(seq) in option.\n");
			else {
		
			}
		} else if(strcmp(argv[2], "add")==0) {
		
			rsp = cmdAddNATRule();
		} else {
		
		}
	} 

	else if(strcmp(argv[1],"conn")==0 && strcmp(argv[2],"ls")==0 ) {
	
	
		
			rsp = getAllConns();
			
			showConns((struct ConnLog*)rsp.data, rsp.arrlen);
			
		} 
		else if(strcmp(argv[1],"default")==0  ) {
	if(strcmp(argv[2],"a")==0)
		rsp = changeDefault(1);
		if(strcmp(argv[2],"d")==0)
			rsp = changeDefault(0);
		} 

}